﻿#include<iostream>
#include<map>
#include<set>
#include"Myset.h"
#include"Mymap.h"
using namespace std;

void testset()
{
	set <int> s;
	int arr[] = { 7,8,2,9,5,6,2,4,9 };
	for (auto e : arr)
	{
		s.insert(e);
	}
	auto it = s.begin();
	while (it != s.end())
	{
		cout << *it << " ";
		++it;
	}
	cout << endl;
	cout << s.erase(2) << endl;
	cout << s.erase(10) << endl;
	it = s.find(11);
	if (it == s.end())
	{
		cout << "查找失败！" << endl;
	}

	cout << s.count(9) << endl;
}

void testmultiset()
{
	multiset<int> ms = { 7,4,8,4,1,2,0,9,8,6,11,15,2,3,4,3,2,4 };
	string  s1[] = { "第五欢","apple","朱文洋","iphone14pro","园游会" };
	string  s2[] = { "xioami","apple","oppo","vivo","redmi" };
	int arr[] = { 7,4,8,4,1,2,0,9,8,6,11,15,2,3,4,3,2,4 };

	/*for (auto e : arr)
	{
		ms.insert(e);
	}*/
	auto it = ms.begin();
	while (it != ms.end())
	{
		cout << *it << " ";
		++it;
	}
	cout << endl;

	cout << ms.erase(2) << endl;
	cout << ms.erase(4) << endl;

	auto pos = ms.find(8);
	auto it1 = pos;
	while (it1 != ms.end())
	{
		cout << *it1 << " ";
		++it1;
	}
	cout << endl;
	cout << ms.erase(2) << endl;
	cout << ms.count(2) << endl;
}
void testmap()
{
	pair<string, string> p = { "apple","苹果" };
	map<string, string> m1 = { p };
	map<string, string>m2 = { pair<string, string>{"banana","香蕉"} };
	map<string, string>m3 = { {"banana","香蕉"},{"apple","苹果" },{"orange","橘子"},{"strawberry","草莓"},{"grape","葡萄"} };
	auto it = m3.begin();
	while (it != m3.end())
	{
		cout << it->first << "->" << it->second << endl;
		++it;
	}
	cout << endl;
	cout << m3.erase("banana") << endl;

	auto it2 = m3.find("apple");
	while (it2 != m3.end())
	{
		cout << it2->first << "->" << it2->second << endl;
		++it2;
	}
	cout << m3.count("apple") << endl;
}

void testmap1()
{


	string str[] = { "香蕉","橘子","草莓","西瓜","哈密瓜","苹果","西瓜","香蕉","草莓","香蕉" };
	map<string, int> m3;
	for (auto e : str)
	{
		m3[e]++;
	}

	auto it = m3.begin();
	while (it != m3.end())
	{
		cout << it->first << "->" << it->second << endl;
		++it;
	}
}


void TestMyset()
{
	Myset<int> s;
	s.insert(4);
	s.insert(6);
	s.insert(9);
	s.insert(7);
	s.insert(8);
	s.insert(3);
	s.insert(5);
	s.insert(1);
	s.insert(2);
	Myset<int>::iterator it = s.end();
	while (it != s.begin())
	{
		--it;
		cout << *it << " ";
		
	}
}

void TestMymap()
{
	//Mymap<int,int> m;
	//int arr[] = { 7,4,8,4,1,2,0,9,8,6,11,15,2,3,4,3,2,4 };
	//for (auto e : arr)
	//{
	//	pair<int,int> pair=make_pair(e, e);
	//	m[e]++;
	//}
	//
	//Mymap<int,int>::iterator it = m.begin();
	//while (it != m.end())
	//{
	//	//it->second = 5;
	//	cout << it->first << " " << it->second << "  ";
	//	++it;
	//}
	//cout << endl;

	string str[] = { "香蕉","橘子","草莓","西瓜","哈密瓜","苹果","西瓜","香蕉","草莓","香蕉" };
	Mymap<string, int> m;
	for (auto& e : str)
	{
		m[e]++;
	}

	auto it = m.begin();
	while (it != m.end())
	{
		cout << it->first << " " << it->second << "  ";
		++it;
	}
	cout << endl;
	
	Mymap<string, int>::iterator  it1 = m.find(make_pair("草莓",10));
	while (it1 != m.end())
	{
		//it->second = 5;
		cout << it1->first << " " << it1->second << "  ";
		++it1;
	}
	cout << endl;
}

void test_map()
{
	Mymap<string, string> dict;
	dict.insert({ "sort", "排序" });
	dict.insert({ "left", "左边" });
	dict.insert({ "right", "右边" });
	dict["left"] = "左边，剩余";
	dict["insert"] = "插入";
	dict["string"];
	Mymap<string, string>::iterator it = dict.begin();
	while (it != dict.end())
	{
		// 不能修改first，可以修改second
		//it->first += 'x';
		it->second += 'x';
		cout << it->first << ":" << it->second << endl;
		++it;
	}
	cout << endl;
}
int main()
{
	TestMymap();
	//TestMyset();
	//test_map();
	return 0;
}


